home *** CD-ROM | disk | FTP | other *** search
/ Giga Games 1 / Giga Games.iso / net / usenet / volume6 / lander < prev    next >
Encoding:
Internet Message Format  |  1989-07-06  |  28.9 KB

  1. Path: uunet!tektronix!tekgen!tekred!games
  2. From: games@tekred.CNA.TEK.COM
  3. Newsgroups: comp.sources.games
  4. Subject: v06i070:  lander - lunar lander simulation for BSD and SysV
  5. Message-ID: <3925@tekred.CNA.TEK.COM>
  6. Date: 1 May 89 18:47:48 GMT
  7. Sender: billr@tekred.CNA.TEK.COM
  8. Lines: 1178
  9. Approved: billr@saab.CNA.TEK.COM
  10.  
  11. Submitted-by: stacey@hcrvax.UUCP
  12. Posting-number: Volume 6, Issue 70
  13. Archive-name: lander
  14.  
  15.  
  16. #! /bin/sh
  17. # This is a shell archive.  Remove anything before this line, then unpack
  18. # it by saving it into a file and typing "sh file".  To overwrite existing
  19. # files, type "sh file -c".  You can also feed this as standard input via
  20. # unshar, or by typing "sh <file", e.g..  If this archive is complete, you
  21. # will see the following message at the end:
  22. #        "End of archive 1 (of 1)."
  23. # Contents:  README Makefile consts.h funcs.h land.c lander.6 move.c
  24. #   score.c screen.c
  25. # Wrapped by billr@saab on Mon May  1 11:44:02 1989
  26. PATH=/bin:/usr/bin:/usr/ucb ; export PATH
  27. if test -f 'README' -a "${1}" != "-c" ; then 
  28.   echo shar: Will not clobber existing file \"'README'\"
  29. else
  30. echo shar: Extracting \"'README'\" \(912 characters\)
  31. sed "s/^X//" >'README' <<'END_OF_FILE'
  32. XThis is a C implementation of the old ``lunar lander''
  33. Xgame seen in amusement arcades in the mid-seventies.
  34. X
  35. XThis version has been ported to various System 5.3
  36. Xsystems, namely 386/ix and HCR's port of System 5.3 to
  37. Xa VAX.  It has also been ported to a version of BSD.
  38. X
  39. XLander utilises some of the nifty SysV.3 curses capabilities
  40. Xsuch as line drawing.  Anyone using an ANSI compatible
  41. Xterminal should see the full effect.  Assorted Visual
  42. Xterminals will give the same results with a decent terminfo
  43. Xfile.  BSD people are stuck with their implementation
  44. Xof curses, but it still looks kind of okay.
  45. X
  46. XLander uses a high score file that is writable by
  47. Xall users running the program, please edit the Makefile to
  48. Xensure a valid name is used.  Lander will attempt to
  49. Xcreate the HS file the first time the game is run and
  50. Xa successful landing is completed.
  51. X
  52. XPlease read the copyright info at the bottom of the man page.
  53. END_OF_FILE
  54. if test 912 -ne `wc -c <'README'`; then
  55.     echo shar: \"'README'\" unpacked with wrong size!
  56. fi
  57. # end of 'README'
  58. fi
  59. if test -f 'Makefile' -a "${1}" != "-c" ; then 
  60.   echo shar: Will not clobber existing file \"'Makefile'\"
  61. else
  62. echo shar: Extracting \"'Makefile'\" \(771 characters\)
  63. sed "s/^X//" >'Makefile' <<'END_OF_FILE'
  64. X# Lander Makefile
  65. X
  66. X# System 5.3
  67. X#
  68. X# OSV=SYS5_3
  69. X# LIBS= -lcurses -lm
  70. X# RAND_L=RAND_SYS5
  71. X
  72. X# BSD Unix
  73. X#
  74. XOSV=BSD
  75. XLIBS= -lcurses -ltermcap -lm
  76. XRAND_L=RAND_BSD
  77. X
  78. X# System 5.2 or earlier (untested but should work)
  79. X#
  80. X# OSV=BSD
  81. X# LIBS= -lcurses -lm
  82. X# RAND_L=RAND_SYS5
  83. X
  84. X# high score file name - change for your system
  85. XHSFILE= /usr/games/lib/lander.hs
  86. X
  87. XOBJS= land.o screen.o move.o score.o
  88. XSRC= land.c screen.c move.c score.c
  89. XINC= consts.h funcs.h
  90. XBIN= $(HOME)/bin
  91. XOPT= -O
  92. XHSSTRING='"$(HSFILE)"'
  93. XCFLAGS= $(OPT) -D$(RAND_L) -DHS_FILE=$(HSSTRING) -D$(OSV)
  94. X
  95. Xlander: $(OBJS)
  96. X    cc -o lander $(CFLAGS) $(OBJS) $(LIBS)
  97. X
  98. X$(OBJS): consts.h
  99. X
  100. Xshar:
  101. X    xshar README lander.6 Makefile $(SRC) $(INC) > lander.shar
  102. X
  103. Xlint:
  104. X    lint $(CFLAGS) $(SRC)
  105. X
  106. Xinstall: lander
  107. X    rm -f $(BIN)/lander
  108. X    cp lander $(BIN)
  109. END_OF_FILE
  110. if test 771 -ne `wc -c <'Makefile'`; then
  111.     echo shar: \"'Makefile'\" unpacked with wrong size!
  112. fi
  113. # end of 'Makefile'
  114. fi
  115. if test -f 'consts.h' -a "${1}" != "-c" ; then 
  116.   echo shar: Will not clobber existing file \"'consts.h'\"
  117. else
  118. echo shar: Extracting \"'consts.h'\" \(1116 characters\)
  119. sed "s/^X//" >'consts.h' <<'END_OF_FILE'
  120. X#define ALTITUDE_INIT 1500.0                   /* initial altitude in metres */
  121. X#define LANDSCAPE_WIDTH 5000.0             /* initial screen width in metres */
  122. X#define PAD '='                    /* landing pad char in template of screen */
  123. X#define CRASH 2                                           /* status of crash */
  124. X#define LANDED 1                 /* status of potentially successful landing */
  125. X#define FLYING 0                                  /* status of flying lander */
  126. X#define GRAVITY 3.2   /* rate of descent in metres per second due to gravity */
  127. X#define ACCEPTABLE 5.0   /* acceptable landing velocity in metres per second */
  128. X#define SCR_Y 22                            /* height of lunarscape in chars */
  129. X#define SCR_X 76                             /* width of lunarscape in chars */
  130. X               /* macro to determine of y and x are legal screen coordinates */
  131. X#define LEGAL_YX(y, x) ((y) < SCR_Y && (x) < SCR_X && (y) >= 0 && (x) >= 0)
  132. X#define SCR_ADJ(y) (y + 1)   /* difference between lunarscape y and screen y */
  133. X#define MAX_PADS 20        /* maximum number of landing pads in a lunarscape */
  134. END_OF_FILE
  135. if test 1116 -ne `wc -c <'consts.h'`; then
  136.     echo shar: \"'consts.h'\" unpacked with wrong size!
  137. fi
  138. # end of 'consts.h'
  139. fi
  140. if test -f 'funcs.h' -a "${1}" != "-c" ; then 
  141.   echo shar: Will not clobber existing file \"'funcs.h'\"
  142. else
  143. echo shar: Extracting \"'funcs.h'\" \(210 characters\)
  144. sed "s/^X//" >'funcs.h' <<'END_OF_FILE'
  145. Xvoid UpdateScore();
  146. Xvoid ScWrite();
  147. Xvoid ScReadDisplay();
  148. Xvoid InitScore();
  149. Xvoid InitialiseScreen();
  150. Xvoid DrawScreen();
  151. Xvoid InitMoves();
  152. Xvoid GetMove();
  153. Xint MoveLander();
  154. Xvoid PressSpace();
  155. Xvoid DrawScreen();
  156. END_OF_FILE
  157. if test 210 -ne `wc -c <'funcs.h'`; then
  158.     echo shar: \"'funcs.h'\" unpacked with wrong size!
  159. fi
  160. # end of 'funcs.h'
  161. fi
  162. if test -f 'land.c' -a "${1}" != "-c" ; then 
  163.   echo shar: Will not clobber existing file \"'land.c'\"
  164. else
  165. echo shar: Extracting \"'land.c'\" \(6926 characters\)
  166. sed "s/^X//" >'land.c' <<'END_OF_FILE'
  167. X#include <stdio.h>
  168. X#include <math.h>
  169. X#include <curses.h>
  170. X#include "consts.h"
  171. X#include "funcs.h"
  172. X
  173. X#define INIT_DX_VAL 166.0                     /* initial horizontal velocity */
  174. X#define INIT_DX_INC 13.0   /* rate of init hor vel increase between landings */
  175. X#define INIT_DY_VAL 0.0                         /* initial vertical velocity */
  176. X#define INIT_DY_INC 3.0    /* rate of decrease in vert velocity b/w landings */
  177. X
  178. Xextern int LastLegalY, LastLegalX;
  179. Xextern int Score, BestScore;
  180. Xextern double FuelDec;
  181. X
  182. Xvoid EndCurses();
  183. Xvoid StartLander();
  184. Xint FlyLander();
  185. Xint CleanUp();
  186. Xvoid Explode();
  187. X
  188. Xint Landings;
  189. Xint BSLandings = 0;
  190. X
  191. Xmain(argc, argv)
  192. X
  193. Xint argc;
  194. Xchar *argv[];
  195. X
  196. X    {
  197. X    double init_dy;                  /* initial rate of fall per landing */
  198. X    double init_dx;           /* initial horizontal velocity per landing */
  199. X    WINDOW *screen;                        /* main display curses window */
  200. X    int LanderStatus;              /* status of lander at end of landing */
  201. X
  202. X    InitialiseScreen(&screen);                   /* do basic screen init */
  203. X    InitScore();
  204. X    do    {
  205. X                                          /* init screen and lander for game */
  206. X        StartLander(&init_dy, &init_dx);
  207. X        do    {
  208. X            InitMoves(screen);    /* init lander for one landing */
  209. X            DrawScreen(screen);   /* init screen for one landing */
  210. X            LanderStatus = FlyLander(screen, init_dy, init_dx);
  211. X            init_dy -= INIT_DY_INC;       /* make landing harder */
  212. X            init_dx += INIT_DX_INC;
  213. X            } while (LanderStatus == LANDED);     /* until crash */
  214. X        } while (CleanUp(screen));  /* while user wants another game */
  215. X    EndCurses(screen);                           /* final screen cleanup */
  216. X    return 0;
  217. X    }
  218. X
  219. X/*
  220. X** StartLander() - initialise a new game.
  221. X*/
  222. X
  223. Xextern int Score;
  224. X
  225. Xstatic void StartLander(init_dy, init_dx)
  226. X
  227. Xdouble *init_dy, *init_dx;
  228. X
  229. X    {
  230. X    Landings = 0;
  231. X    Score = 0;
  232. X    FuelDec = 0.0;
  233. X    *init_dy = INIT_DY_VAL;
  234. X    *init_dx = INIT_DX_VAL;
  235. X    }
  236. X
  237. X/*
  238. X** EndCurses() - final cleanup before program exit.
  239. X*/
  240. X
  241. Xstatic void EndCurses(screen)
  242. X
  243. X    {
  244. X    nodelay(screen, FALSE);                        /* switch off nodelay */
  245. X    wmove(screen, 1, 0);
  246. X    wclrtoeol(screen);                             /* display best score */
  247. X    wprintw(screen, "--Best Score: %d ", BestScore);
  248. X    wprintw(screen, "with %d landing%s - press space--", BSLandings,
  249. X        BSLandings == 1 ? "" : "s");
  250. X    wrefresh(screen);
  251. X    while (wgetch(screen) != ' ');
  252. X    endwin();                                        /* shut down curses */
  253. X    }
  254. X
  255. Xstatic int CleanUp(screen)
  256. X
  257. XWINDOW *screen;
  258. X
  259. X    {
  260. X    char ch;
  261. X
  262. X    nodelay(screen, FALSE);
  263. X    if (Score > BestScore)
  264. X        {
  265. X        BestScore = Score;
  266. X        BSLandings = Landings;
  267. X        }
  268. X    ScWrite(screen);
  269. X    ScReadDisplay(screen);
  270. X    wmove(screen, 1, 0);
  271. X    wprintw(screen, "--Game Over - Safe Landings: %d - another game?--",
  272. X        Landings);
  273. X    wrefresh(screen);
  274. X    do    {
  275. X        ch = wgetch(screen);
  276. X        } while (ch != 'Y' && ch != 'y' && ch != ' ' && ch != 'n');
  277. X    return ch == 'Y' || ch == 'y' || ch == ' ';
  278. X    }
  279. X
  280. Xstatic int FlyLander(screen, y_move, x_move)
  281. X
  282. XWINDOW *screen;
  283. Xdouble y_move, x_move;
  284. X
  285. X    {
  286. X    int land_stat;
  287. X    double altitude = ALTITUDE_INIT;
  288. X    double longditude = 0.0;
  289. X
  290. X    for (land_stat = FLYING; land_stat == FLYING;)
  291. X        {
  292. X        sleep(1);
  293. X        GetMove(screen, &y_move, &x_move);
  294. X        land_stat = MoveLander(screen, altitude, longditude);
  295. X        switch (land_stat)
  296. X            {
  297. X            case FLYING :
  298. X            y_move -= GRAVITY;
  299. X            altitude += y_move;
  300. X            if (altitude < 0.0)
  301. X                altitude = 0.0;
  302. X            longditude += x_move;
  303. X            break;
  304. X            case LANDED :
  305. X            if (y_move < -(ACCEPTABLE))
  306. X                {
  307. X                Explode(screen, LastLegalY, LastLegalX);
  308. X                land_stat = CRASH;
  309. X                }
  310. X            else
  311. X                UpdateScore(screen);
  312. X            break;
  313. X            case CRASH :
  314. X            Explode(screen, LastLegalY, LastLegalX);
  315. X            break;
  316. X            }
  317. X        wmove(screen, 0, 0);
  318. X        wclrtoeol(screen);
  319. X        wprintw(screen,
  320. X            "alt: %8.3f X: %8.2f dY: %7.3f dX: %7.3f Score: %5d",
  321. X            altitude, longditude, y_move, x_move, Score);
  322. X        wrefresh(screen);
  323. X        }
  324. X    if (land_stat == LANDED)
  325. X        {
  326. X        ++Landings;
  327. X        nodelay(screen, FALSE);
  328. X        wmove(screen, 1, 0);
  329. X        wprintw(screen, "--Safe Landing Number: %d", Landings);
  330. X        waddstr(screen, " - press space bar--");
  331. X#ifdef BSD
  332. X        wrefresh(screen);
  333. X#endif
  334. X        while (wgetch(screen) != ' ');
  335. X        nodelay(screen, TRUE);
  336. X        }
  337. X    return land_stat;
  338. X    }
  339. X
  340. X#define SEQ_COUNT (sizeof(sequenceA) / sizeof(sequenceA[0]))
  341. X#define AVERAGE 9
  342. X#define DEVIATION 4
  343. X#define MAX_PARTS (AVERAGE + DEVIATION)
  344. Xstatic char sequenceA[] = {'-', '/', '|', '\\'};
  345. Xstatic char sequenceB[] = {'-', '\\', '|', '/'};
  346. X
  347. Xstatic void Explode(screen, Y_bang, X_bang)
  348. X
  349. XWINDOW *screen;
  350. Xint Y_bang, X_bang;
  351. X
  352. X    {
  353. X    int particles, i, new_y, new_x, draw_y, draw_x, touched, toy, tox;
  354. X    int overlay[SCR_Y][SCR_X];
  355. X#ifdef BSD
  356. X    int old_chs[SCR_Y][SCR_X];
  357. X#else
  358. X    chtype old_chs[SCR_Y][SCR_X];
  359. X#endif
  360. X    double x_inc;
  361. X    struct paths_t {
  362. X        double x_mult;
  363. X        double y_mult;
  364. X        double x;
  365. X        int old_y;
  366. X        int old_x;
  367. X        int seq_no;
  368. X        char *sequence;
  369. X        } paths[MAX_PARTS];
  370. X    struct paths_t *path;
  371. X    long lrand48(), time();
  372. X    double drand48();
  373. X    void srand48();
  374. X
  375. X    wstandout(screen);
  376. X    mvwaddch(screen, SCR_ADJ(Y_bang), X_bang, '*');
  377. X    wstandend(screen);
  378. X    wrefresh(screen);
  379. X    srand48(time((long *) 0));
  380. X    memset((char *)overlay, 0, sizeof(overlay));
  381. X    particles = (AVERAGE + lrand48() % DEVIATION);
  382. X    x_inc = M_PI_2 * (drand48() * 0.01 + 0.01);
  383. X    for (i = 0; i < particles; ++i)
  384. X        {
  385. X        path = &paths[i];
  386. X        path->x = 0.0;
  387. X        path->x_mult = drand48() * (double) SCR_X * 0.2;
  388. X        path->y_mult = drand48() * (double) SCR_Y * 1.1 + 5.0;
  389. X        path->old_y = -1;
  390. X        path->old_x = -1;
  391. X        path->seq_no = lrand48() % SEQ_COUNT;
  392. X        path->sequence = i & 1 ? sequenceA : sequenceB;
  393. X        flash();
  394. X        }
  395. X    while (paths[0].x < M_PI)
  396. X        for (i = 0; i < particles; ++i)
  397. X            {
  398. X            touched = 0;
  399. X            path = &paths[i];
  400. X            new_x = path->x * path->x_mult + 0.5;
  401. X            if (i & 1)
  402. X                new_x = -new_x;
  403. X            new_y = sin(path->x) * path->y_mult + 0.5;
  404. X            draw_y = Y_bang - new_y;
  405. X            draw_x = X_bang + new_x;
  406. X            toy = path->old_y;
  407. X            tox = path->old_x;
  408. X            if (LEGAL_YX(toy, tox))
  409. X                if (!(--overlay[toy][tox]))
  410. X                    {
  411. X                    touched = 1;
  412. X                    mvwaddch(screen, SCR_ADJ(toy), tox,
  413. X                        old_chs[toy][tox]);
  414. X                    }
  415. X            if (LEGAL_YX(draw_y, draw_x))
  416. X                {
  417. X                wmove(screen, SCR_ADJ(draw_y), draw_x);
  418. X                if (!overlay[draw_y][draw_x])
  419. X                    old_chs[draw_y][draw_x] = winch(screen);
  420. X                waddch(screen,
  421. X                    path->sequence[path->seq_no++ % SEQ_COUNT]);
  422. X                ++overlay[draw_y][draw_x];
  423. X                touched = 1;
  424. X                }
  425. X            if (touched)
  426. X                {
  427. X#ifdef SYS5_3
  428. X                flushinp();
  429. X#endif
  430. X                wrefresh(screen);
  431. X                }
  432. X            path->old_y = draw_y;
  433. X            path->old_x = draw_x;
  434. X            path->x += x_inc;
  435. X            }
  436. X    for (i = 0; i < particles; ++i)
  437. X        {
  438. X        path = &paths[i];
  439. X        toy = path->old_y;
  440. X        tox = path->old_x;
  441. X        if (LEGAL_YX(toy, tox))
  442. X            mvwaddch(screen, SCR_ADJ(toy), tox, old_chs[toy][tox]);
  443. X        }
  444. X    wrefresh(screen);
  445. X    }
  446. X
  447. X#if defined(RAND_BSD)
  448. Xstatic long lrand48()
  449. X
  450. X    {
  451. X    long random();
  452. X
  453. X    return random();
  454. X    }
  455. X
  456. Xstatic void srand48(seed)
  457. X
  458. Xlong seed;
  459. X
  460. X    {
  461. X    srandom((int) seed);
  462. X    }
  463. X
  464. X#define PERIOD (4096 - 1)
  465. X
  466. Xstatic double drand48()
  467. X
  468. X    {
  469. X    return random() % PERIOD / (double) PERIOD;
  470. X    }
  471. X#endif
  472. END_OF_FILE
  473. if test 6926 -ne `wc -c <'land.c'`; then
  474.     echo shar: \"'land.c'\" unpacked with wrong size!
  475. fi
  476. # end of 'land.c'
  477. fi
  478. if test -f 'lander.6' -a "${1}" != "-c" ; then 
  479.   echo shar: Will not clobber existing file \"'lander.6'\"
  480. else
  481. echo shar: Extracting \"'lander.6'\" \(1205 characters\)
  482. sed "s/^X//" >'lander.6' <<'END_OF_FILE'
  483. X.TH Lander 6l
  484. X.SH NAME
  485. Xlander \- the arcade game
  486. X.SH DESCRIPTION
  487. X.I Lander
  488. Xis an implementation of the ancient ``lunar lander'' arcade
  489. Xgame.
  490. X.PP
  491. XThe object of the game is to gently land a lunar module on
  492. Xthe lunar surface.  Landing with a vertical velocity greater
  493. Xthan 5 metres per second will generally result in fragmentation of the
  494. Xlander and loss of cabin pressure!
  495. X.PP
  496. XScoring is based on which landing pad you choose, how much
  497. Xfuel you conserved during landing and the difficulty factor
  498. Xof landing from higher entry velocities as the game progresses.
  499. X.PP
  500. XOperating instructions are provided on the initial screen of
  501. X.I lander.
  502. XA high score file is maintained.
  503. X.SH BUGS
  504. XNone known, but please send bug reports to {utzoo,utcsri,lsuc}!hcr!stacey.
  505. X.SH AUTHOR
  506. XStacey Campbell \- HCR Corporation, Toronto, Canada, 1989.
  507. X.SH DISCLAIMER
  508. XLander is copyright 1989 by HCR Corporation, Toronto, Ontario, Canada.
  509. XPermission to use, copy, modify, and distribute this software and
  510. Xits documentation for any purpose and without fee is hereby
  511. Xgranted, provided that the above copyright notice appear in all
  512. Xcopies.
  513. X.PP
  514. XHCR  Corporation  disclaims all  warranties with regard to
  515. Xthis software. Use at your own risk.
  516. END_OF_FILE
  517. if test 1205 -ne `wc -c <'lander.6'`; then
  518.     echo shar: \"'lander.6'\" unpacked with wrong size!
  519. fi
  520. # end of 'lander.6'
  521. fi
  522. if test -f 'move.c' -a "${1}" != "-c" ; then 
  523.   echo shar: Will not clobber existing file \"'move.c'\"
  524. else
  525. echo shar: Extracting \"'move.c'\" \(1760 characters\)
  526. sed "s/^X//" >'move.c' <<'END_OF_FILE'
  527. X#include <fcntl.h>
  528. X#include <stdio.h>
  529. X#include <ctype.h>
  530. X#include <math.h>
  531. X#include <curses.h>
  532. X#include "consts.h"
  533. X#include "funcs.h"
  534. X
  535. X#if defined(BSD) && ! defined(O_NDELAY)
  536. X#define NO_INP -1
  537. X#else
  538. X#define NO_INP EOF
  539. X#endif
  540. X
  541. X#define FABS_M(x) ((x) >= -1.0 ? 1.0 : -(x))
  542. X#define FUEL_INIT 5000.0
  543. X#define FUEL_DRAIN 450.0
  544. X#define FUEL_MIN 100.0
  545. X
  546. Xdouble Fuel;
  547. Xdouble FuelDec = 0.0;
  548. X
  549. Xstatic double Power;
  550. Xstatic double PowerSet[] = {0.0, 0.01, 0.1, 0.5, 1.0, 2.0, 5.0, 10.0,
  551. X    15.0, 20.0};
  552. Xstatic double att1p, att2p, att3p;
  553. X
  554. Xvoid InitMoves(screen)
  555. X
  556. XWINDOW *screen;
  557. X
  558. X    {
  559. X    att1p = 0.0;
  560. X    att2p = 0.0;
  561. X    att3p = 0.0;
  562. X    Power = 0.0;
  563. X    Fuel = FUEL_INIT - FuelDec;
  564. X    if (Fuel < FUEL_MIN)
  565. X        Fuel = FUEL_MIN;
  566. X    FuelDec += FUEL_DRAIN;
  567. X    nodelay(screen, TRUE);
  568. X    }
  569. X
  570. Xvoid GetMove(screen, y_delta, x_delta)
  571. X
  572. XWINDOW *screen;
  573. Xdouble *y_delta, *x_delta;
  574. X
  575. X    {
  576. X    int ch, index;
  577. X    double y_delta_inc;
  578. X
  579. X    if (Fuel > 0.0)
  580. X        {
  581. X        wrefresh(screen);
  582. X        while ((ch = wgetch(screen)) != NO_INP)
  583. X            {
  584. X#ifdef BSD
  585. X            ch &= 0x7F;
  586. X#endif
  587. X            if (isdigit(ch))
  588. X                {
  589. X                index = ch - '0';
  590. X                Power = PowerSet[index];
  591. X                }
  592. X            else
  593. X                switch (ch)
  594. X                    {
  595. X                    case 'z' :
  596. X                    att1p = Power;
  597. X                    break;
  598. X                    case 'x' :
  599. X                    att2p = Power;
  600. X                    break;
  601. X                    case 'c' :
  602. X                    att3p = Power;
  603. X                    break;
  604. X                    default :
  605. X                    flash();
  606. X                    break;
  607. X                    }
  608. X            }
  609. X        *x_delta += att1p;
  610. X        y_delta_inc = att2p * (log10(FABS_M(*y_delta)) / GRAVITY);
  611. X        *y_delta += y_delta_inc;
  612. X        *x_delta -= att3p;
  613. X        Fuel -= att3p + att2p + att1p;
  614. X        if (Fuel < 0.0)
  615. X            att3p = att2p = att1p = Power = Fuel = 0.0;
  616. X        }
  617. X    wmove(screen, LINES - 1, 0);
  618. X    wclrtoeol(screen);
  619. X    wprintw(screen,
  620. X            "Thrust - L: %5.2f vert: %7.4f R: %5.2f Pow: %5.2f Fuel: %7.2f",
  621. X        att1p, att2p, att3p, Power, Fuel);
  622. X    wrefresh(screen);
  623. X    }
  624. END_OF_FILE
  625. if test 1760 -ne `wc -c <'move.c'`; then
  626.     echo shar: \"'move.c'\" unpacked with wrong size!
  627. fi
  628. # end of 'move.c'
  629. fi
  630. if test -f 'score.c' -a "${1}" != "-c" ; then 
  631.   echo shar: Will not clobber existing file \"'score.c'\"
  632. else
  633. echo shar: Extracting \"'score.c'\" \(4844 characters\)
  634. sed "s/^X//" >'score.c' <<'END_OF_FILE'
  635. X#include <stdio.h>
  636. X#include <curses.h>
  637. X#include "consts.h"
  638. X#include "funcs.h"
  639. X
  640. X#define HEADER "Scores"
  641. X#define NAME_LEN 20
  642. X#define HS_ENTRIES 10
  643. X#define SC_WIN_LEN 16
  644. X#define SPC_LINE (SC_WIN_LEN - 2)
  645. X
  646. Xtypedef struct score_pad_t {
  647. X    int y;
  648. X    int start_x;
  649. X    int end_x;
  650. X    } score_pad_t;
  651. Xtypedef struct score_t {
  652. X    int score;
  653. X    char name[NAME_LEN];
  654. X    } score_t;
  655. X
  656. Xextern double Fuel;
  657. Xextern int PadScore[];
  658. Xextern int BSLandings, Landings;
  659. Xextern char *Template[];
  660. Xextern int LastLegalY, LastLegalX;
  661. X
  662. Xscore_pad_t ScorePad[MAX_PADS];
  663. Xint Score;
  664. Xint BestScore = 0;
  665. X
  666. Xstatic char *HSFile = HS_FILE;
  667. Xstatic int TotalPads;
  668. X
  669. Xvoid ScDisplayErr();
  670. Xint ScCmp();
  671. X
  672. Xvoid ScReadDisplay(back_win)
  673. X
  674. XWINDOW *back_win;
  675. X
  676. X    {
  677. X    int old_y, old_x, items, i;
  678. X    WINDOW *score_win;
  679. X    FILE *fp;
  680. X    score_t score_pad[HS_ENTRIES];
  681. X
  682. X    if ((fp = fopen(HSFile, "r")) == NULL)
  683. X        {
  684. X        ScDisplayErr(back_win, "Unable to display HS file.");
  685. X        return;
  686. X        }
  687. X    getyx(back_win, old_y, old_x);
  688. X    wmove(back_win, 0, 0);
  689. X    wrefresh(back_win);
  690. X    score_win = newwin(SC_WIN_LEN, 25, 2, 5);
  691. X    werase(score_win);
  692. X    box(score_win, 0, 0);
  693. X    items = fread((char *)score_pad, sizeof(score_t), HS_ENTRIES, fp);
  694. X    fclose(fp);
  695. X    if (items == 0)
  696. X        {
  697. X        mvwaddstr(score_win, 5, 1, "HS file empty.");
  698. X        PressSpace(back_win, old_y, old_x, score_win, SPC_LINE, 1);
  699. X        return;
  700. X        }
  701. X    mvwaddstr(score_win, 1, (25 - sizeof(HEADER)) / 2, HEADER);
  702. X    wrefresh(score_win);
  703. X    for (i = 0; i < items; ++i)
  704. X        {
  705. X        wmove(score_win, 3 + i, 1);
  706. X        wprintw(score_win, "%4d %s", score_pad[i].score,
  707. X            score_pad[i].name);
  708. X        }
  709. X    PressSpace(back_win, old_y, old_x, score_win, SPC_LINE, 1);
  710. X    }
  711. X
  712. Xvoid ScWrite(back_win)
  713. X
  714. XWINDOW *back_win;
  715. X
  716. X    {
  717. X    int items;
  718. X    FILE *fp;
  719. X    char *user;
  720. X    score_t score_pad[HS_ENTRIES + 1];
  721. X    void qsort();
  722. X    char *getenv();
  723. X
  724. X    if (Score == 0)
  725. X        return;
  726. X    if ((fp = fopen(HSFile, "r")) == NULL)
  727. X        {
  728. X        ScDisplayErr(back_win, "Unable to read HS file.");
  729. X        ScDisplayErr(back_win, "Attempting to create HS file.");
  730. X        if (creat(HSFile, 0777) == -1)
  731. X            {
  732. X            ScDisplayErr(back_win,
  733. X                "Unable to create HS file, check pathname.");
  734. X            return;
  735. X            }
  736. X        }
  737. X    if ((fp = fopen(HSFile, "r")) == NULL)
  738. X        {
  739. X        ScDisplayErr(back_win, "Unable to read new HS file.");
  740. X        return;
  741. X        }
  742. X    items = fread((char *)score_pad, sizeof(score_t), HS_ENTRIES, fp);
  743. X    fclose(fp);
  744. X    if ((user = getenv("LOGNAME")) == NULL)
  745. X        {
  746. X        ScDisplayErr(back_win, "Environment var LOGNAME must be set");
  747. X        return;
  748. X        }
  749. X    strcpy(score_pad[items].name, user);
  750. X    score_pad[items].score = Score;
  751. X    ++items;
  752. X    qsort((char *)score_pad, items, sizeof(score_t), ScCmp);
  753. X    if (items > HS_ENTRIES)
  754. X        items = HS_ENTRIES;
  755. X    if ((fp = fopen(HSFile, "w")) == NULL)
  756. X        {
  757. X        ScDisplayErr(back_win, "Unable to write HS file.");
  758. X        return;
  759. X        }
  760. X    if (fwrite((char *)score_pad, sizeof(score_t), items, fp) == 0)
  761. X        ScDisplayErr(back_win, "No HS entries written.");
  762. X    fclose(fp);
  763. X    }
  764. X
  765. Xstatic int ScCmp(sc_rec1, sc_rec2)
  766. X
  767. Xscore_t *sc_rec1, *sc_rec2;
  768. X
  769. X    {
  770. X    if (sc_rec1->score < sc_rec2->score)
  771. X        return 1;
  772. X    if (sc_rec1->score > sc_rec2->score)
  773. X        return -1;
  774. X    return 0;
  775. X    }
  776. X
  777. Xvoid PressSpace(back_win, y, x, cur_win, sy, sx)
  778. X
  779. XWINDOW *back_win, *cur_win;
  780. Xint y, x, sy, sx;
  781. X
  782. X    {
  783. X    mvwaddstr(cur_win, sy, sx, "--press space--");
  784. X    wrefresh(cur_win);
  785. X    while (wgetch(cur_win) != ' ');
  786. X    delwin(cur_win);
  787. X    wmove(back_win, y, x);
  788. X    touchwin(back_win);
  789. X    wrefresh(back_win);
  790. X    }
  791. X
  792. Xstatic void ScDisplayErr(back_win, str)
  793. X
  794. XWINDOW *back_win;
  795. Xchar *str;
  796. X
  797. X    {
  798. X    int old_y, old_x, win_len;
  799. X    WINDOW *err_win;
  800. X
  801. X    getyx(back_win, old_y, old_x);
  802. X    wmove(back_win, 0, 0);
  803. X    wrefresh(back_win);
  804. X    win_len = strlen(str) + 2;
  805. X    err_win = newwin(3, win_len, LINES / 2 - 2, (COLS - win_len - 2) / 2);
  806. X    box(err_win, 0, 0);
  807. X    mvwaddstr(err_win, 1, 1, str);
  808. X    wrefresh(err_win);
  809. X    sleep(3);
  810. X    delwin(err_win);
  811. X    wmove(back_win, old_y, old_x);
  812. X    touchwin(back_win);
  813. X    wrefresh(back_win);
  814. X    }
  815. X
  816. Xvoid UpdateScore(screen)
  817. X
  818. XWINDOW *screen;
  819. X
  820. X    {
  821. X    int pad_i = 0, found = 0, fuel_bonus, diff_bonus;
  822. X    char scr_buf[128];
  823. X
  824. X    while (pad_i < SCR_X && ! found)
  825. X        {
  826. X        found = LastLegalX >= ScorePad[pad_i].start_x &&
  827. X            LastLegalX <= ScorePad[pad_i].end_x &&
  828. X            ScorePad[pad_i].y == LastLegalY;
  829. X        ++pad_i;
  830. X        }
  831. X    --pad_i;
  832. X    fuel_bonus = Fuel / 100.0 + 0.5;
  833. X    sprintf(scr_buf, "Fuel bonus: %d", fuel_bonus);
  834. X    mvwaddstr(screen, 3, 25, scr_buf);
  835. X    wrefresh(screen);
  836. X    diff_bonus = (Landings + 1) * 10;
  837. X    sprintf(scr_buf, "Consecutive Landings Bonus: %d", diff_bonus);
  838. X    mvwaddstr(screen, 4, 9, scr_buf);
  839. X    wrefresh(screen);
  840. X    Score += PadScore[pad_i] + fuel_bonus + diff_bonus;
  841. X    }
  842. X
  843. Xvoid InitScore()
  844. X
  845. X    {
  846. X    int i, j, pad_count = 0;
  847. X    char *line;
  848. X
  849. X    for (i = 0; i < SCR_Y; ++i)
  850. X        {
  851. X        j = 0;
  852. X        line = Template[i];
  853. X        while (j < SCR_X)
  854. X            {
  855. X            if (line[j] == PAD)
  856. X                {
  857. X                ScorePad[pad_count].y = i;
  858. X                ScorePad[pad_count].start_x = j;
  859. X                while (j < SCR_X && line[j] == PAD)
  860. X                    ++j;
  861. X                if (j >= SCR_X)
  862. X                    --j;
  863. X                ScorePad[pad_count].end_x = j;
  864. X                ++pad_count;
  865. X                }
  866. X            ++j;
  867. X            }
  868. X        }
  869. X    TotalPads = pad_count;
  870. X    }
  871. END_OF_FILE
  872. if test 4844 -ne `wc -c <'score.c'`; then
  873.     echo shar: \"'score.c'\" unpacked with wrong size!
  874. fi
  875. # end of 'score.c'
  876. fi
  877. if test -f 'screen.c' -a "${1}" != "-c" ; then 
  878.   echo shar: Will not clobber existing file \"'screen.c'\"
  879. else
  880. echo shar: Extracting \"'screen.c'\" \(6384 characters\)
  881. sed "s/^X//" >'screen.c' <<'END_OF_FILE'
  882. X#include <signal.h>
  883. X#include <fcntl.h>
  884. X#include <stdio.h>
  885. X#include <curses.h>
  886. X#include "consts.h"
  887. X#include "funcs.h"
  888. X
  889. X#define ALT_ADD(screen, y, x, ch) \
  890. X    wmove(screen, y, x); \
  891. X    waddch(screen, ch);
  892. X#define STAND_ADD(screen, y, x, ch) \
  893. X    wmove(screen, y, x); \
  894. X    wstandout(screen); \
  895. X    waddch(screen, ch); \
  896. X    wstandend(screen);
  897. X#define STAND_ALT_ADD(screen, y, x, ch) \
  898. X    wstandout(screen); \
  899. X    ALT_ADD(screen, y, x, ch); \
  900. X    wstandend(screen);
  901. X
  902. Xchar *Template[] = {
  903. X"                                                                            ",
  904. X".                                                                          /",
  905. X"<                                                                        /v+",
  906. X"<                                                                       /+++",
  907. X"<                                                                     /v++++",
  908. X"<                            /====.                                   >+++++",
  909. X"<                            `v30v<                                  /++++++",
  910. X"<                             >++++.                                 >++++++",
  911. X"<                             >++++<                                /+++++++",
  912. X"<                             >++++<                               /++++++++",
  913. X"+.                            >+++++.                              `++++++++",
  914. X"+<                           /++++++<                               `+++++++",
  915. X"+<                          /+++++++<                                >++++++",
  916. X"+<                          >+++++++<                          /v.   >++++++",
  917. X"+<                          >+++++++<                         /+++.  >++++++",
  918. X"+<                          >+++++++'                         >+++<  >++++++",
  919. X"++====.                /====+++++++<                          >+++<  >++++++",
  920. X"++v30v<            /vvv+v15v+++++++<          /v.           /v++++<  >++++++",
  921. X"+++++++v.       /vv++++++++++++++++<        /v+++====.      >++++++==+++++++",
  922. X"+++++++++=======+++++++++++++++++++<      /v+++++v20v+======+++++++50+++++++",
  923. X"+++++++++vv10vvv++++++++++++++++++++======++++++++++++vv15vv++++++++++++++++",
  924. X"++++++++++++++++++++++++++++++++++++vv25vv++++++++++++++++++++++++++++++++++"};
  925. X
  926. Xint PadScore[MAX_PADS] = {30, 30, 15, 20, 50, 10, 15, 25};
  927. Xint LastLegalY, LastLegalX;
  928. X
  929. X#ifdef BSD
  930. Xtypedef char chtype_port_t;
  931. X#else
  932. Xtypedef chtype chtype_port_t;
  933. X#endif
  934. X
  935. Xstatic chtype_port_t LineMap[128] = {0};
  936. Xstatic int Old_Y, Old_X;
  937. X
  938. Xvoid Introduction();
  939. Xvoid dumpcore();
  940. Xvoid zap();
  941. X
  942. Xvoid InitialiseScreen(init_scr)
  943. X
  944. XWINDOW **init_scr;
  945. X
  946. X    {
  947. X    register WINDOW *screen;
  948. X
  949. X    signal(SIGINT, zap);
  950. X    signal(SIGQUIT, dumpcore);
  951. X    initscr();
  952. X    noecho();
  953. X    cbreak();
  954. X    *init_scr = stdscr;
  955. X    screen = *init_scr;
  956. X#ifdef BSD
  957. X    LineMap['\''] = '+';
  958. X    LineMap['.'] = '+';
  959. X    LineMap['|'] = '|';
  960. X    LineMap['-'] = '-';
  961. X    LineMap['/'] = '+';
  962. X    LineMap['`'] = '+';
  963. X    LineMap['+'] = '+';
  964. X    LineMap['>'] = '+';
  965. X    LineMap['<'] = '+';
  966. X    LineMap['^'] = '+';
  967. X    LineMap['v'] = '+';
  968. X    LineMap[PAD] = '=';
  969. X#else
  970. X    LineMap['\''] = ACS_LRCORNER;
  971. X    LineMap['.'] = ACS_URCORNER;
  972. X    LineMap['|'] = ACS_VLINE;
  973. X    LineMap['-'] = ACS_HLINE;
  974. X    LineMap['/'] = ACS_ULCORNER;
  975. X    LineMap['`'] = ACS_LLCORNER;
  976. X    LineMap['+'] = ACS_PLUS;
  977. X    LineMap['>'] = ACS_LTEE;
  978. X    LineMap['<'] = ACS_RTEE;
  979. X    LineMap['^'] = ACS_BTEE;
  980. X    LineMap['v'] = ACS_TTEE;
  981. X    LineMap[PAD] = ACS_HLINE;
  982. X#endif
  983. X    Introduction(screen);
  984. X    }
  985. X
  986. Xvoid DrawScreen(screen)
  987. X
  988. XWINDOW *screen;
  989. X
  990. X    {
  991. X    register int i, j, scr_i;
  992. X    chtype_port_t map;
  993. X    char *line, ch;
  994. X
  995. X    werase(screen);
  996. X    for (i = 0; i < SCR_Y; ++i)
  997. X        {
  998. X        line = Template[i];
  999. X        scr_i = i + 1;
  1000. X        for (j = 0; j < SCR_X; ++j)
  1001. X            {
  1002. X            ch = *(line + j);
  1003. X            map = LineMap[ch];
  1004. X            if (map)
  1005. X                if (ch == PAD)
  1006. X                    {
  1007. X                    STAND_ALT_ADD(screen, scr_i, j, map);
  1008. X                    }
  1009. X                else
  1010. X                    {
  1011. X                    ALT_ADD(screen, scr_i, j, map);
  1012. X                    }
  1013. X            else
  1014. X                if (ch == PAD)
  1015. X                    {
  1016. X                    STAND_ADD(screen, scr_i, j, ch);
  1017. X                    }
  1018. X                else
  1019. X                    mvwaddch(screen, scr_i, j, ch);
  1020. X            }
  1021. X        }
  1022. X    wrefresh(screen);
  1023. X    LastLegalY = SCR_ADJ(0);
  1024. X    LastLegalX = 0;
  1025. X    Old_Y = Old_X = -1;
  1026. X    }
  1027. X
  1028. Xint MoveLander(screen, land_y, land_x)
  1029. X
  1030. XWINDOW *screen;
  1031. Xdouble land_y, land_x;
  1032. X
  1033. X    {
  1034. X    int y, x, touchup = 0, screen_y, new_legal;
  1035. X    double y_real, x_real;
  1036. X    char ch;
  1037. X
  1038. X    y_real = (ALTITUDE_INIT - land_y) / ALTITUDE_INIT * (double) SCR_Y;
  1039. X    x_real = land_x / LANDSCAPE_WIDTH * (double) SCR_X;
  1040. X    y = y_real + 0.5;
  1041. X    x = x_real + 0.5;
  1042. X    new_legal = LEGAL_YX(y, x);
  1043. X    if (y != Old_Y || x != Old_X)
  1044. X        {
  1045. X        if (LEGAL_YX(Old_Y, Old_X))
  1046. X            {
  1047. X            mvwaddch(screen, SCR_ADJ(Old_Y), Old_X, '.');
  1048. X            touchup = 1;
  1049. X            }
  1050. X        if (new_legal)
  1051. X            {
  1052. X            screen_y = SCR_ADJ(y);
  1053. X#ifdef BSD
  1054. X            ALT_ADD(screen, screen_y, x, '$');
  1055. X#else
  1056. X            ALT_ADD(screen, screen_y, x, ACS_TTEE);
  1057. X#endif
  1058. X            wmove(screen, screen_y, x);
  1059. X            LastLegalY = y;
  1060. X            LastLegalX = x;
  1061. X            touchup = 1;
  1062. X            }
  1063. X        }
  1064. X    if (touchup)
  1065. X        wrefresh(screen);
  1066. X    Old_Y = y;
  1067. X    Old_X = x;
  1068. X    if (new_legal)
  1069. X        {
  1070. X        ch = *(Template[y] + x);
  1071. X        if (ch == PAD)
  1072. X            return LANDED;
  1073. X        if (ch != ' ')
  1074. X            return CRASH;
  1075. X        }
  1076. X    else
  1077. X        return CRASH;
  1078. X    return FLYING;
  1079. X    }
  1080. X
  1081. Xstatic void zap()
  1082. X
  1083. X    {
  1084. X    endwin();
  1085. X    fcntl(fileno(stdin), F_SETFL, 0);
  1086. X    exit(1);
  1087. X    }
  1088. X
  1089. Xstatic void dumpcore()
  1090. X
  1091. X    {
  1092. X    fcntl(fileno(stdin), F_SETFL, 0);
  1093. X    endwin();
  1094. X    signal(SIGQUIT, SIG_DFL);
  1095. X    kill(getpid(), SIGQUIT);
  1096. X    pause();
  1097. X    }
  1098. X
  1099. X#define L0 "Lunar Lander"
  1100. X#define L1 "The classic arcade game comes to Unix."
  1101. X#define L2 "Controls:"
  1102. X#define L3 "'0'-'9' - power level"
  1103. X#define L4 "'z' - set left retro rocket to power level"
  1104. X#define L5 "'x' - set vertical thrust to power level"
  1105. X#define L6 "'c' - set right retro to power level"
  1106. X#define L7 "--press space to start game--"
  1107. X#define L8 "Stacey Campbell at HCR, 1989"
  1108. X#define CENTRE(win, line, str) mvwaddstr(win, line, (COLS - sizeof(str)) / 2, \
  1109. X    str)
  1110. X
  1111. Xstatic void Introduction(screen)
  1112. X
  1113. XWINDOW *screen;
  1114. X
  1115. X    {
  1116. X    werase(screen);
  1117. X    CENTRE(screen, 2, L0);
  1118. X    CENTRE(screen, 5, L1);
  1119. X    CENTRE(screen, 9, L2);
  1120. X    CENTRE(screen, 11, L3);
  1121. X    CENTRE(screen, 12, L4);
  1122. X    CENTRE(screen, 13, L5);
  1123. X    CENTRE(screen, 14, L6);
  1124. X    CENTRE(screen, 18, L8);
  1125. X    CENTRE(screen, 20, L7);
  1126. X#ifdef BSD
  1127. X    wrefresh(screen);
  1128. X#endif
  1129. X    while (wgetch(screen) != ' ');
  1130. X    }
  1131. X
  1132. X#ifdef BSD
  1133. X
  1134. Xint flash()
  1135. X
  1136. X    {
  1137. X    putchar(7);
  1138. X    }
  1139. X
  1140. X#ifndef FNDELAY
  1141. X#define FNDELAY O_NDELAY
  1142. X#endif
  1143. X
  1144. Xint nodelay(win, flag)
  1145. X
  1146. XWINDOW *win;
  1147. Xint flag;
  1148. X
  1149. X    {
  1150. X    int res;
  1151. X
  1152. X    res = fcntl(fileno(stdin), F_GETFL, 0);
  1153. X    if (flag)
  1154. X        {
  1155. X        res |=  FNDELAY;
  1156. X        fcntl(fileno(stdin), F_SETFL, res);
  1157. X        }
  1158. X    else
  1159. X        {
  1160. X        res &= ~FNDELAY;
  1161. X        fcntl(fileno(stdin), F_SETFL, res);
  1162. X        }
  1163. X    return 0;
  1164. X    }
  1165. X#endif
  1166. END_OF_FILE
  1167. if test 6384 -ne `wc -c <'screen.c'`; then
  1168.     echo shar: \"'screen.c'\" unpacked with wrong size!
  1169. fi
  1170. # end of 'screen.c'
  1171. fi
  1172. echo shar: End of archive 1 \(of 1\).
  1173. cp /dev/null ark1isdone
  1174. MISSING=""
  1175. for I in 1 ; do
  1176.     if test ! -f ark${I}isdone ; then
  1177.     MISSING="${MISSING} ${I}"
  1178.     fi
  1179. done
  1180. if test "${MISSING}" = "" ; then
  1181.     echo You have the archive.
  1182.     rm -f ark[1-9]isdone
  1183. else
  1184.     echo You still need to unpack the following archives:
  1185.     echo "        " ${MISSING}
  1186. fi
  1187. ##  End of shell archive.
  1188. exit 0
  1189.